package com.cn.shiro.zy.shiro.exception;

import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author zhangyi
 * @date 2018/12/12 17:55
 */
@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(UnauthenticatedException.class)
    public String nauthenticatedException(Model model){
        model.addAttribute("errorMsg","当前无用户！");
        return "nonauth";
    }
    @ExceptionHandler(UnauthorizedException.class)
    public String nauthorizedException(Model model){
        model.addAttribute("errorMsg","当前用户没有权限");
        return "nonauth";
    }
}
